home *** CD-ROM | disk | FTP | other *** search
/ Just Call Me Internet / Just Call Me Internet.iso / prog / atari / c / nos042_s / pppdump.c < prev    next >
C/C++ Source or Header  |  1994-09-16  |  3KB  |  112 lines

  1. /*
  2.  *    PPPDUMP.C
  3.  *
  4.  *    12-89    -- Katie Stevens (dkstevens@ucdavis.edu)
  5.  *           UC Davis, Computing Services
  6.  *    PPP.08    05-90    [ks] improve tracing reports
  7.  *    PPP.09  05-90    [ks] add UPAP packet reporting
  8.  *    PPP.14    08-90    [ks] change UPAP to PAP for consistency with RFC1172
  9.  *    PPP.15    09-90    [ks] update to KA9Q NOS v900828
  10.  *    Jan 91    [Bill Simpson] small changes to match rewrite of PPP
  11.  *    Aug 91    [Bill Simpson] fixed some buffer loss
  12.  */
  13.  
  14. /****************************************************************************
  15. *    $Id: pppdump.c 1.2 93/07/16 11:49:02 ROOT_DOS Exp $
  16. *    14 Jul 93    1.2        GT    Fix warnings.                                    *
  17. ****************************************************************************/
  18.  
  19. #include <stdio.h>
  20. #include "global.h"
  21. #include "mbuf.h"
  22. #include "iface.h"
  23. #include "internet.h"
  24. #include "ppp.h"
  25. #include "trace.h"
  26. #include "ip.h"
  27.  
  28. #ifdef TURBOC_SWITCH_BUG
  29. #pragma option -G-
  30. #endif
  31.  
  32. /* dump a PPP packet */
  33. void
  34. ppp_dump(fp,bpp,unused)
  35. FILE *fp;
  36. struct mbuf **bpp;
  37. int unused;
  38. {
  39.     struct ppp_hdr hdr;
  40.     struct mbuf *tbp;
  41.  
  42.     fprintf(fp,"PPP: len %3u\t", len_p(*bpp));
  43.  
  44.     /* HDLC address and control fields may be compressed out */
  45.     if ((byte_t)(*bpp)->data[0] != HDLC_ALL_ADDR) {
  46.         fprintf(fp,"(compressed ALL/UI)\t");
  47.     } else if ((byte_t)(*bpp)->data[1] != HDLC_UI) {
  48.         fprintf(fp,"(missing UI!)\t");
  49.     } else {
  50.         /* skip address/control fields */
  51.         pull16(bpp);
  52.     }
  53.  
  54.     /* Initialize the expected header */
  55.     hdr.addr = HDLC_ALL_ADDR;
  56.     hdr.control = HDLC_UI;
  57.     hdr.protocol = PULLCHAR(bpp);
  58.  
  59.     /* First byte of PPP protocol field may be compressed out */
  60.     if ( hdr.protocol & 0x01 ) {
  61.         fprintf(fp,"compressed ");
  62.     } else {
  63.         hdr.protocol = (hdr.protocol << 8) | PULLCHAR(bpp);
  64.  
  65.         /* Second byte of PPP protocol field must be odd */
  66.         if ( !(hdr.protocol & 0x01) ) {
  67.             fprintf(fp, "(not odd!) " );
  68.         }
  69.     }
  70.  
  71.     fprintf(fp,"protocol: ");
  72.     switch(hdr.protocol){
  73.         case PPP_IP_PROTOCOL:
  74.             fprintf(fp,"IP\n");
  75.             ip_dump(fp,bpp,1);
  76.             break;
  77.         case PPP_IPCP_PROTOCOL:
  78.             fprintf(fp,"IPCP\n");
  79.             break;
  80.         case PPP_LCP_PROTOCOL:
  81.             fprintf(fp,"LCP\n");
  82.             break;
  83.         case PPP_PAP_PROTOCOL:
  84.             fprintf(fp,"PAP\n");
  85.             break;
  86.         case PPP_COMPR_PROTOCOL:
  87.             fprintf(fp,"VJ Compressed TCP/IP\n");
  88.             vjcomp_dump(fp,bpp,0);
  89.             break;
  90.         case PPP_UNCOMP_PROTOCOL:
  91.             fprintf(fp,"VJ Uncompressed TCP/IP\n");
  92.             /* Get our own copy so we can mess with the data */
  93.             if ( (tbp = copy_p(*bpp, len_p(*bpp))) == NULLBUF)
  94.                 return;
  95.  
  96.             fprintf(fp,"\tconnection 0x%02x\n",
  97.                 tbp->data[9]);        /* FIX THIS! */
  98.             /* Restore the bytes used with Uncompressed TCP */
  99.             tbp->data[9] = TCP_PTCL;    /* FIX THIS! */
  100.             ip_dump(fp,&tbp,1);
  101.             free_p(tbp);
  102.             break;
  103.         default:
  104.             fprintf(fp,"unknown 0x%04x\n",hdr.protocol);
  105.             break;
  106.     }
  107. }
  108.  
  109. #ifdef TURBOC_SWITCH_BUG
  110. #pragma option -G
  111. #endif
  112.